<template>
  <div class="home_content light">
    <component is="defaultLayout2"
               :userInfo="currentUserInfo.loginUser"
               :screenBtns="screenBtns"
               :MenuList="MenuList"
               :currentRoute="currentRoute"
               :routeParams="routeParams"
               title="水利报表"
    ></component>
  </div>
</template>

<script lang="ts" setup>
// @ts-ignore
import {getCurrentInstance, onMounted, ref} from 'vue'
// @ts-ignore
const {proxy} = getCurrentInstance()

const layout = ref('');

const currentUserInfo = ref({loginUser: {}, access: [], screenBtn: [], systemMenus: [], platformMenus: []});
// 菜单列表
const MenuList = ref<any>([])
// 当前属性的路由
const currentRoute = ref("");
// 当前刷新路由的参数
const routeParams = ref<any>([]);
//大屏按钮
const screenBtns = ref<any>([]);

onMounted(() => {
  proxy.$NProgress.start();
  if (proxy.$store.getters.token) {
    getUserInfo();
  } else {
    proxy.$NProgress.done();
    proxy.$router.push("/login");
  }
})

const getUserInfo = () => {
  proxy.$http.post('/user-center/cloud/user/', {}).then((res: any) => {
    if (res) {
      currentUserInfo.value = res.data;
      proxy.$store.dispatch('setCurrentUser', currentUserInfo.value.loginUser);
      proxy.$store.dispatch('setPermission', currentUserInfo.value.access);
      screenBtns.value = currentUserInfo.value.screenBtn;
      routeParams.value = proxy.$route.params.path;
      currentRoute.value = proxy.$route.fullPath;
      MenuList.value = currentUserInfo.value.platformMenus;
      proxy.$NProgress.done();
    } else {
      proxy.$NProgress.done();
      proxy.$router.push("/login");
    }
  }).catch((error: any) => {
    proxy.$NProgress.done();

    proxy.$router.push("/login");
  });
}
</script>
